Imports System
Imports System.Data
Imports System.Collections
Imports System.Collections.Generic

Imports Framework

<Serializable(), CLSCompliant(True)> _
Partial Public Class CProductType
    Inherits SchemaAudit.CBaseDynamicAudited
    Implements IComparable(Of CProductType)

#Region "Constructors"
    'Public (Copy Constructor)
    Public Sub New(ByVal original as CProductType, target As CDataSrc)
        m_dataSrc = target
        m_typeName = original.TypeName
        m_typeParentTypeId = original.TypeParentTypeId
        m_typeParentIsRequired = original.TypeParentIsRequired
        m_typeIsFree = original.TypeIsFree
        m_typeCanHaveAudio = original.TypeCanHaveAudio
        m_typeCanHavePdfOrWord = original.TypeCanHavePdfOrWord
        m_typeCanHaveHtmlNotesOrPreview = original.TypeCanHaveHtmlNotesOrPreview
        m_typeCanHaveVimeo = original.TypeCanHaveVimeo
        m_typeCanHaveTranscript = original.TypeCanHaveTranscript
        m_typeDescription = original.TypeDescription
    End Sub

    'Protected (Datareader/Dataset)
    Protected Sub New(ByVal dataSrc As CDataSrc, ByVal dr As IDataReader)
        MyBase.New(dataSrc, dr)
    End Sub
    Protected Sub New(ByVal dataSrc As CDataSrc, ByVal dr As DataRow)
        MyBase.New(dataSrc, dr)
    End Sub
#End Region

#Region "Default Values"
    Protected Overrides Sub InitValues_Auto()
        'Null-Equivalent values (except String.Empty, as nulls tend to be inconvenient for string types)
        m_typeId = 0
        m_typeName = String.Empty
        m_typeParentTypeId = 0
        m_typeParentIsRequired = False
        m_typeIsFree = False
        m_typeCanHaveAudio = False
        m_typeCanHavePdfOrWord = False
        m_typeCanHaveHtmlNotesOrPreview = False
        m_typeCanHaveVimeo = False
        m_typeCanHaveTranscript = False
        m_typeDescription = String.Empty
    End Sub
#End Region

#Region "Members"
    Protected m_typeId As Byte
    Protected m_typeName As String
    Protected m_typeParentTypeId As Byte
    Protected m_typeParentIsRequired As Boolean
    Protected m_typeIsFree As Boolean
    Protected m_typeCanHaveAudio As Boolean
    Protected m_typeCanHavePdfOrWord As Boolean
    Protected m_typeCanHaveHtmlNotesOrPreview As Boolean
    Protected m_typeCanHaveVimeo As Boolean
    Protected m_typeCanHaveTranscript As Boolean
    Protected m_typeDescription As String
#End Region

#Region "Properties - Column Values"
    'Primary Key Column (ReadOnly)
    Public ReadOnly Property [TypeId]() As Byte
        Get
            Return m_typeId
        End Get
    End Property

    'Table Columns (Read/Write)
    Public Property [TypeName]() As String
        Get
            Return m_typeName
        End Get
        Set(ByVal value As String)
            m_typeName = value
        End Set
    End Property
    Public Property [TypeParentTypeId]() As Byte
        Get
            Return m_typeParentTypeId
        End Get
        Set(ByVal value As Byte)
            m_typeParentTypeId = value
        End Set
    End Property
    Public Property [TypeParentIsRequired]() As Boolean
        Get
            Return m_typeParentIsRequired
        End Get
        Set(ByVal value As Boolean)
            m_typeParentIsRequired = value
        End Set
    End Property
    Public Property [TypeIsFree]() As Boolean
        Get
            Return m_typeIsFree
        End Get
        Set(ByVal value As Boolean)
            m_typeIsFree = value
        End Set
    End Property
    Public Property [TypeCanHaveAudio]() As Boolean
        Get
            Return m_typeCanHaveAudio
        End Get
        Set(ByVal value As Boolean)
            m_typeCanHaveAudio = value
        End Set
    End Property
    Public Property [TypeCanHavePdfOrWord]() As Boolean
        Get
            Return m_typeCanHavePdfOrWord
        End Get
        Set(ByVal value As Boolean)
            m_typeCanHavePdfOrWord = value
        End Set
    End Property
    Public Property [TypeCanHaveHtmlNotesOrPreview]() As Boolean
        Get
            Return m_typeCanHaveHtmlNotesOrPreview
        End Get
        Set(ByVal value As Boolean)
            m_typeCanHaveHtmlNotesOrPreview = value
        End Set
    End Property
    Public Property [TypeCanHaveVimeo]() As Boolean
        Get
            Return m_typeCanHaveVimeo
        End Get
        Set(ByVal value As Boolean)
            m_typeCanHaveVimeo = value
        End Set
    End Property
    Public Property [TypeCanHaveTranscript]() As Boolean
        Get
            Return m_typeCanHaveTranscript
        End Get
        Set(ByVal value As Boolean)
            m_typeCanHaveTranscript = value
        End Set
    End Property
    Public Property [TypeDescription]() As String
        Get
            Return m_typeDescription
        End Get
        Set(ByVal value As String)
            m_typeDescription = value
        End Set
    End Property

    'View Columns (ReadOnly)

#End Region

#Region "MustOverride Methods"
    'Schema Information
    Public Const TABLE_NAME As String = "tblMcm_ProductTypes"
    Public Const VIEW_NAME As String  = ""          'Used to override Me.ViewName
    Public Const ORDER_BY_COLS As String = "TypeId" 'See the CompareTo method below (Sql-based sorting should match In-Memory sorting)
    Public Const SORTING_COLUMN As String = ""
    Public Overrides ReadOnly Property TableName() As String
        Get
            Return TABLE_NAME
        End Get
    End Property
    Protected Overrides ReadOnly Property OrderByColumns() As String
        Get
            Return ORDER_BY_COLS
        End Get
    End Property

    'CompareTo Interface (Default Sort Order)
    Public Function CompareTo(other As CProductType) As Integer Implements IComparable(Of CProductType).CompareTo
        Return Me.TypeId.CompareTo(other.TypeId) 
    End Function

    'Primary Key Information
    Public Const PRIMARY_KEY_NAME As String = "TypeId"
    Protected Overrides ReadOnly Property InsertPrimaryKey() As Boolean
        Get
            Return False
        End Get
    End Property
    Protected Overrides ReadOnly Property PrimaryKeyName() As String
        Get
            Return PRIMARY_KEY_NAME
        End Get
    End Property
    Protected Overrides Property PrimaryKeyValue() As Object
        Get
            Return m_typeId
        End Get
        Set(ByVal value As Object)
            m_typeId = CType(Value, Byte)
        End Set
    End Property

    'Factory Methods - Object
    Protected Overrides Function MakeFrom(ByVal row As DataRow) As CBase
        Return New CProductType(Me.DataSrc, row)
    End Function
    Protected Overrides Function MakeFrom(ByVal dr As IDataReader) As CBase
        Return New CProductType(Me.DataSrc, dr)
    End Function
    
    'Factory Methods - List
    Protected Overrides Function MakeList() As IList
        Return New CProductTypeList
    End Function
    Protected Overrides Function MakeList(ByVal capacity As Integer) As IList
        Return New CProductTypeList(capacity)
    End Function

    'Convert from ADO to .Net
    Protected Overrides Sub ReadColumns(ByVal dr As IDataReader)
        m_typeId = CAdoData.GetByte(dr, "TypeId")
        m_typeName = CAdoData.GetStr(dr, "TypeName")
        m_typeParentTypeId = CAdoData.GetByte(dr, "TypeParentTypeId")
        m_typeParentIsRequired = CAdoData.GetBool(dr, "TypeParentIsRequired")
        m_typeIsFree = CAdoData.GetBool(dr, "TypeIsFree")
        m_typeCanHaveAudio = CAdoData.GetBool(dr, "TypeCanHaveAudio")
        m_typeCanHavePdfOrWord = CAdoData.GetBool(dr, "TypeCanHavePdfOrWord")
        m_typeCanHaveHtmlNotesOrPreview = CAdoData.GetBool(dr, "TypeCanHaveHtmlNotesOrPreview")
        m_typeCanHaveVimeo = CAdoData.GetBool(dr, "TypeCanHaveVimeo")
        m_typeCanHaveTranscript = CAdoData.GetBool(dr, "TypeCanHaveTranscript")
        m_typeDescription = CAdoData.GetStr(dr, "TypeDescription")
    End Sub
    Protected Overrides Sub ReadColumns(ByVal dr As DataRow)
        m_typeId = CAdoData.GetByte(dr, "TypeId")
        m_typeName = CAdoData.GetStr(dr, "TypeName")
        m_typeParentTypeId = CAdoData.GetByte(dr, "TypeParentTypeId")
        m_typeParentIsRequired = CAdoData.GetBool(dr, "TypeParentIsRequired")
        m_typeIsFree = CAdoData.GetBool(dr, "TypeIsFree")
        m_typeCanHaveAudio = CAdoData.GetBool(dr, "TypeCanHaveAudio")
        m_typeCanHavePdfOrWord = CAdoData.GetBool(dr, "TypeCanHavePdfOrWord")
        m_typeCanHaveHtmlNotesOrPreview = CAdoData.GetBool(dr, "TypeCanHaveHtmlNotesOrPreview")
        m_typeCanHaveVimeo = CAdoData.GetBool(dr, "TypeCanHaveVimeo")
        m_typeCanHaveTranscript = CAdoData.GetBool(dr, "TypeCanHaveTranscript")
        m_typeDescription = CAdoData.GetStr(dr, "TypeDescription")
    End Sub

    'Parameters for Insert/Update    
    Protected Overrides Function ColumnNameValues() As CNameValueList
        Dim data As New CNameValueList
        data.Add("TypeId", NullVal(m_typeId))
        data.Add("TypeName", NullVal(m_typeName))
        data.Add("TypeParentTypeId", NullVal(m_typeParentTypeId))
        data.Add("TypeParentIsRequired", NullVal(m_typeParentIsRequired))
        data.Add("TypeIsFree", NullVal(m_typeIsFree))
        data.Add("TypeCanHaveAudio", NullVal(m_typeCanHaveAudio))
        data.Add("TypeCanHavePdfOrWord", NullVal(m_typeCanHavePdfOrWord))
        data.Add("TypeCanHaveHtmlNotesOrPreview", NullVal(m_typeCanHaveHtmlNotesOrPreview))
        data.Add("TypeCanHaveVimeo", NullVal(m_typeCanHaveVimeo))
        data.Add("TypeCanHaveTranscript", NullVal(m_typeCanHaveTranscript))
        data.Add("TypeDescription", NullVal(m_typeDescription))
        Return data
    End Function
#End Region

#Region "Queries - SelectAll/SelectWhere (inherited methods, cast only)"
    'Select Queries - Non-Paged
    Public Shadows Function SelectAll() As CProductTypeList
        Return CType(MyBase.SelectAll(), CProductTypeList)
    End Function
    Public Shadows Function SelectAll(ByVal orderBy As String) As CProductTypeList
        Return CType(MyBase.SelectAll(orderBy), CProductTypeList)
    End Function
    Protected Shadows Function SelectWhere(ByVal colName As String, ByVal sign As ESign, ByVal colValue As Object) As CProductTypeList
        Return CType(MyBase.SelectWhere(colName, sign, colValue), CProductTypeList)
    End Function
    Protected Shadows Function SelectWhere(ByVal where As CCriteria) As CProductTypeList
        Return CType(MyBase.SelectWhere(where), CProductTypeList)
    End Function
    Protected Shadows Function SelectWhere(ByVal where As CCriteriaList) As CProductTypeList
        Return CType(MyBase.SelectWhere(where), CProductTypeList)
    End Function
    Protected Shadows Function SelectWhere(ByVal where As CCriteriaList, ByVal tableNameOrJoinExpression As String) As CProductTypeList
        Return CType(MyBase.SelectWhere(where, tableNameOrJoinExpression, Me.OrderByColumns), CProductTypeList)
    End Function
    Protected Shadows Function SelectWhere(ByVal where As CCriteriaList, ByVal tableNameOrJoinExpression As String, ByVal orderBy As String) As CProductTypeList
        Return CType(MyBase.SelectWhere(where, tableNameOrJoinExpression, orderBy), CProductTypeList)
    End Function
    <Obsolete("Arbitrary where-clause is not necessary portable or safe from sql injection attacks. Consider using the parameterised query interfaces")> _
    Protected Shadows Function SelectWhere(ByVal unsafeWhereClause As String) As CProductTypeList
        Return CType(MyBase.SelectWhere(unsafeWhereClause), CProductTypeList)
    End Function
    Protected Shadows Function SelectById(ByVal typeId As Byte) As CProductTypeList
        Return CType(MyBase.SelectById(typeId), CProductTypeList)
    End Function
    Protected Shadows Function SelectByIds(ByVal ids As List(Of Byte)) As CProductTypeList
        Return CType(MyBase.SelectByIds(ids), CProductTypeList)
    End Function

    'Select Queries - Paged
    Public Shadows Function SelectAll(ByVal pi As CPagingInfo) As CProductTypeList
        Return CType(MyBase.SelectAll(pi), CProductTypeList)
    End Function
    Protected Shadows Function SelectWhere(ByVal pi As CPagingInfo, ByVal colName As String, ByVal sign As ESign, ByVal colValue As Object) As CProductTypeList
        Return CType(MyBase.SelectWhere(pi, colName, sign, colValue), CProductTypeList)
    End Function
    Protected Shadows Function SelectWhere(ByVal pi As CPagingInfo, ByVal criteria As CCriteria) As CProductTypeList
        Return CType(MyBase.SelectWhere(pi, criteria), CProductTypeList)
    End Function
    Protected Shadows Function SelectWhere(ByVal pi As CPagingInfo, ByVal criteria As CCriteriaList) As CProductTypeList
        Return CType(MyBase.SelectWhere(pi, criteria), CProductTypeList)
    End Function
    Protected Shadows Function SelectWhere(ByVal pi As CPagingInfo, ByVal criteria As CCriteriaList, ByVal tableViewOrJoinExpr As String) As CProductTypeList
        Return CType(MyBase.SelectWhere(pi, criteria, tableViewOrJoinExpr), CProductTypeList)
    End Function
    Protected Shadows Function SelectByIds(ByVal pi As CPagingInfo, ByVal ids As List(Of Byte)) As CProductTypeList
        Return CType(MyBase.SelectByIds(pi, ids), CProductTypeList)
    End Function

    'Select Queries - Transactional (Friend-scoped for use in cascade-deletes)
    Friend Shadows Function SelectAll(ByVal tx As IDbTransaction) As CProductTypeList
        Return CType(MyBase.SelectAll(tx), CProductTypeList)
    End Function
    Friend Shadows Function SelectWhere(ByVal columnName As String, columnValue As Object, ByVal tx As IDbTransaction) As CProductTypeList
        Return CType(MyBase.SelectWhere(columnName, columnValue, tx), CProductTypeList)
    End Function
    Friend Shadows Function SelectWhere(ByVal columnName As String, sign As ESign, columnValue As Object, ByVal tx As IDbTransaction) As CProductTypeList
        Return CType(MyBase.SelectWhere(columnName, sign, columnValue, tx), CProductTypeList)
    End Function
    Friend Shadows Function SelectWhere(ByVal criteria As CCriteria, ByVal tx As IDbTransaction) As CProductTypeList
        Return CType(MyBase.SelectWhere(criteria, tx), CProductTypeList)
    End Function
    Friend Shadows Function SelectWhere(ByVal criteria As CCriteriaList, ByVal tx As IDbTransaction) As CProductTypeList
        Return CType(MyBase.SelectWhere(criteria, tx), CProductTypeList)
    End Function
    Friend Shadows Function SelectWhere(ByVal criteria As CCriteriaList, ByVal tableOrJoin As String, ByVal tx As IDbTransaction) As CProductTypeList
        Return CType(MyBase.SelectWhere(criteria, tableOrJoin, tx), CProductTypeList)
    End Function
    Friend Shadows Function SelectWhere(ByVal criteria As CCriteriaList, ByVal tableOrJoin As String, ByVal orderBy As String, ByVal tx As IDbTransaction) As CProductTypeList
        Return CType(MyBase.SelectWhere(criteria, tableOrJoin, orderBy, tx), CProductTypeList)
    End Function
    Friend Shadows Function SelectById(ByVal typeId As Byte, ByVal tx As IDbTransaction) As CProductTypeList
        Return CType(MyBase.SelectById(typeId, tx), CProductTypeList)
    End Function
    Friend Shadows Function SelectByIds(ByVal ids As List(Of Byte), ByVal tx As IDbTransaction) As CProductTypeList
        Return CType(MyBase.SelectByIds(ids, tx), CProductTypeList)
    End Function
    
    'Select Queries - Stored Procedures
    Protected Overloads Function MakeList(ByVal storedProcName As String, ByVal txOrNull As IDbTransaction) As CProductTypeList
        Return CType(MyBase.MakeList(storedProcName,         txOrNull), CProductTypeList)
    End Function
    Protected Overloads Function MakeList(ByVal storedProcName As String, ByVal params As Object(), ByVal txOrNull As IDbTransaction) As CProductTypeList
        Return CType(MyBase.MakeList(storedProcName, params, txOrNull), CProductTypeList)
    End Function
    Protected Overloads Function MakeList(ByVal storedProcName As String, ByVal params As CNameValueList, ByVal txOrNull As IDbTransaction) As CProductTypeList
        Return CType(MyBase.MakeList(storedProcName, params, txOrNull), CProductTypeList)
    End Function
    Protected Overloads Function MakeList(ByVal storedProcName As String, ByVal params As List(Of Object), ByVal txOrNull As IDbTransaction) As CProductTypeList
        Return CType(MyBase.MakeList(storedProcName, params, txOrNull), CProductTypeList)
    End Function
    Protected Overloads Function MakeList(ByVal storedProcName As String, ByVal param1 As Integer, ByVal txOrNull As IDbTransaction) As CProductTypeList
        Return CType(MyBase.MakeList(storedProcName, param1, txOrNull), CProductTypeList)
    End Function
    Protected Overloads Function MakeList(ByVal storedProcName As String, ByVal param1 As String, ByVal txOrNull As IDbTransaction) As CProductTypeList
        Return CType(MyBase.MakeList(storedProcName, param1, txOrNull), CProductTypeList)
    End Function

    'Query Results
    Protected Overloads Function MakeList(ByVal ds As DataSet) As CProductTypeList
        Return CType(MyBase.MakeList(ds), CProductTypeList)
    End Function
    Protected Overloads Function MakeList(ByVal dt As DataTable) As CProductTypeList
        Return CType(MyBase.MakeList(dt), CProductTypeList)
    End Function
    Protected Overloads Function MakeList(ByVal rows As DataRowCollection) As CProductTypeList
        Return CType(MyBase.MakeList(rows), CProductTypeList)
    End Function
    Protected Overloads Function MakeList(ByVal dr As IDataReader) As CProductTypeList
        Return CType(MyBase.MakeList(dr), CProductTypeList)
    End Function
    Protected Overloads Function MakeList(ByVal drOrDs As Object) As CProductTypeList
        Return CType(MyBase.MakeList(drOrDs), CProductTypeList)
    End Function
    Protected Overloads Function MakeList(ByVal gzip As Byte()) As CProductTypeList
        Return CType(MyBase.MakeList(gzip), CProductTypeList)
    End Function
#End Region

#Region "Queries - SelectBy[FK] (user-nominated fk/bool columns)"
    'Note: These methods should only be used for cascade-deletes, or initialising the cache. Use CProductType.Cache.GetBy... for reqular queries
    
    'Non-Paged
    Protected Function SelectByParentTypeId(ByVal typeParentTypeId As Byte) As CProductTypeList
        Return SelectWhere(new CCriteriaList("TypeParentTypeId", typeParentTypeId))
    End Function
    Protected Function SelectByParentIsRequired(ByVal typeParentIsRequired As Boolean) As CProductTypeList
        Return SelectWhere(new CCriteriaList("TypeParentIsRequired", typeParentIsRequired))
    End Function
    Protected Function SelectByIsFree(ByVal typeIsFree As Boolean) As CProductTypeList
        Return SelectWhere(new CCriteriaList("TypeIsFree", typeIsFree))
    End Function
    Protected Function SelectByCanHaveAudio(ByVal typeCanHaveAudio As Boolean) As CProductTypeList
        Return SelectWhere(new CCriteriaList("TypeCanHaveAudio", typeCanHaveAudio))
    End Function
    Protected Function SelectByCanHavePdfOrWord(ByVal typeCanHavePdfOrWord As Boolean) As CProductTypeList
        Return SelectWhere(new CCriteriaList("TypeCanHavePdfOrWord", typeCanHavePdfOrWord))
    End Function
    Protected Function SelectByCanHaveHtmlNotesOrPreview(ByVal typeCanHaveHtmlNotesOrPreview As Boolean) As CProductTypeList
        Return SelectWhere(new CCriteriaList("TypeCanHaveHtmlNotesOrPreview", typeCanHaveHtmlNotesOrPreview))
    End Function
    Protected Function SelectByCanHaveVimeo(ByVal typeCanHaveVimeo As Boolean) As CProductTypeList
        Return SelectWhere(new CCriteriaList("TypeCanHaveVimeo", typeCanHaveVimeo))
    End Function
    Protected Function SelectByCanHaveTranscript(ByVal typeCanHaveTranscript As Boolean) As CProductTypeList
        Return SelectWhere(new CCriteriaList("TypeCanHaveTranscript", typeCanHaveTranscript))
    End Function

    'Paged
    Protected Function SelectByParentTypeId(pi as CPagingInfo, ByVal typeParentTypeId As Byte) As CProductTypeList
        Return SelectWhere(pi, New CCriteriaList("TypeParentTypeId", typeParentTypeId))
    End Function
    Protected Function SelectByParentIsRequired(pi as CPagingInfo, ByVal typeParentIsRequired As Boolean) As CProductTypeList
        Return SelectWhere(pi, New CCriteriaList("TypeParentIsRequired", typeParentIsRequired))
    End Function
    Protected Function SelectByIsFree(pi as CPagingInfo, ByVal typeIsFree As Boolean) As CProductTypeList
        Return SelectWhere(pi, New CCriteriaList("TypeIsFree", typeIsFree))
    End Function
    Protected Function SelectByCanHaveAudio(pi as CPagingInfo, ByVal typeCanHaveAudio As Boolean) As CProductTypeList
        Return SelectWhere(pi, New CCriteriaList("TypeCanHaveAudio", typeCanHaveAudio))
    End Function
    Protected Function SelectByCanHavePdfOrWord(pi as CPagingInfo, ByVal typeCanHavePdfOrWord As Boolean) As CProductTypeList
        Return SelectWhere(pi, New CCriteriaList("TypeCanHavePdfOrWord", typeCanHavePdfOrWord))
    End Function
    Protected Function SelectByCanHaveHtmlNotesOrPreview(pi as CPagingInfo, ByVal typeCanHaveHtmlNotesOrPreview As Boolean) As CProductTypeList
        Return SelectWhere(pi, New CCriteriaList("TypeCanHaveHtmlNotesOrPreview", typeCanHaveHtmlNotesOrPreview))
    End Function
    Protected Function SelectByCanHaveVimeo(pi as CPagingInfo, ByVal typeCanHaveVimeo As Boolean) As CProductTypeList
        Return SelectWhere(pi, New CCriteriaList("TypeCanHaveVimeo", typeCanHaveVimeo))
    End Function
    Protected Function SelectByCanHaveTranscript(pi as CPagingInfo, ByVal typeCanHaveTranscript As Boolean) As CProductTypeList
        Return SelectWhere(pi, New CCriteriaList("TypeCanHaveTranscript", typeCanHaveTranscript))
    End Function

    'Count
    Protected Function SelectCountByParentTypeId(ByVal typeParentTypeId As Byte) As Integer
        Return SelectCount(New CCriteriaList("TypeParentTypeId", typeParentTypeId))
    End Function
    Protected Function SelectCountByParentIsRequired(ByVal typeParentIsRequired As Boolean) As Integer
        Return SelectCount(New CCriteriaList("TypeParentIsRequired", typeParentIsRequired))
    End Function
    Protected Function SelectCountByIsFree(ByVal typeIsFree As Boolean) As Integer
        Return SelectCount(New CCriteriaList("TypeIsFree", typeIsFree))
    End Function
    Protected Function SelectCountByCanHaveAudio(ByVal typeCanHaveAudio As Boolean) As Integer
        Return SelectCount(New CCriteriaList("TypeCanHaveAudio", typeCanHaveAudio))
    End Function
    Protected Function SelectCountByCanHavePdfOrWord(ByVal typeCanHavePdfOrWord As Boolean) As Integer
        Return SelectCount(New CCriteriaList("TypeCanHavePdfOrWord", typeCanHavePdfOrWord))
    End Function
    Protected Function SelectCountByCanHaveHtmlNotesOrPreview(ByVal typeCanHaveHtmlNotesOrPreview As Boolean) As Integer
        Return SelectCount(New CCriteriaList("TypeCanHaveHtmlNotesOrPreview", typeCanHaveHtmlNotesOrPreview))
    End Function
    Protected Function SelectCountByCanHaveVimeo(ByVal typeCanHaveVimeo As Boolean) As Integer
        Return SelectCount(New CCriteriaList("TypeCanHaveVimeo", typeCanHaveVimeo))
    End Function
    Protected Function SelectCountByCanHaveTranscript(ByVal typeCanHaveTranscript As Boolean) As Integer
        Return SelectCount(New CCriteriaList("TypeCanHaveTranscript", typeCanHaveTranscript))
    End Function

    'Transactional
    Friend Function SelectByParentTypeId(ByVal typeParentTypeId As Byte, tx As IDbTransaction) As CProductTypeList
        Return SelectWhere(New CCriteriaList("TypeParentTypeId", typeParentTypeId), tx)
    End Function
    Friend Function SelectByParentIsRequired(ByVal typeParentIsRequired As Boolean, tx As IDbTransaction) As CProductTypeList
        Return SelectWhere(New CCriteriaList("TypeParentIsRequired", typeParentIsRequired), tx)
    End Function
    Friend Function SelectByIsFree(ByVal typeIsFree As Boolean, tx As IDbTransaction) As CProductTypeList
        Return SelectWhere(New CCriteriaList("TypeIsFree", typeIsFree), tx)
    End Function
    Friend Function SelectByCanHaveAudio(ByVal typeCanHaveAudio As Boolean, tx As IDbTransaction) As CProductTypeList
        Return SelectWhere(New CCriteriaList("TypeCanHaveAudio", typeCanHaveAudio), tx)
    End Function
    Friend Function SelectByCanHavePdfOrWord(ByVal typeCanHavePdfOrWord As Boolean, tx As IDbTransaction) As CProductTypeList
        Return SelectWhere(New CCriteriaList("TypeCanHavePdfOrWord", typeCanHavePdfOrWord), tx)
    End Function
    Friend Function SelectByCanHaveHtmlNotesOrPreview(ByVal typeCanHaveHtmlNotesOrPreview As Boolean, tx As IDbTransaction) As CProductTypeList
        Return SelectWhere(New CCriteriaList("TypeCanHaveHtmlNotesOrPreview", typeCanHaveHtmlNotesOrPreview), tx)
    End Function
    Friend Function SelectByCanHaveVimeo(ByVal typeCanHaveVimeo As Boolean, tx As IDbTransaction) As CProductTypeList
        Return SelectWhere(New CCriteriaList("TypeCanHaveVimeo", typeCanHaveVimeo), tx)
    End Function
    Friend Function SelectByCanHaveTranscript(ByVal typeCanHaveTranscript As Boolean, tx As IDbTransaction) As CProductTypeList
        Return SelectWhere(New CCriteriaList("TypeCanHaveTranscript", typeCanHaveTranscript), tx)
    End Function
#End Region

#Region "Static - Cache Implementation"
    Public Shared Property Cache() As CProductTypeList
        Get
            Cache = CType(CCache.Get(CACHE_KEY), CProductTypeList)
            If IsNothing(cache) Then
                SyncLock (CACHE_KEY)
                    Cache = CType(CCache.Get(CACHE_KEY), CProductTypeList)
                    If IsNothing(cache) Then
                        Cache = LoadCache()
                        CProductType.Cache = Cache
                    End If
                End SyncLock
            End If
            Return cache
        End Get
        Set(ByVal value As CProductTypeList)
            SetCache(value)
        End Set
    End Property

    'Change Management:
    'Clone, modify, and then replace the cache (threadsafe for anything iterating the collection)
    'Note that internal indices are dicarded each time unless handled in constructor and add/remove overrides
    Protected Overrides Sub CacheDelete()
        If CacheIsNull Then Exit Sub
        SyncLock (CACHE_KEY)
            Dim temp As CProductTypeList = New CProductTypeList(Cache)
            Dim size As Integer = temp.Count
            temp.Remove(Me)
            If size = temp.Count Then 'Remove might fail If cache was refreshed with New instances. Use old index                    
                temp.Remove(CacheGetById(temp))
            End If
            SetCache(temp)
        End SyncLock
    End Sub
    Protected Overrides Sub CacheInsert()
        If CacheIsNull Then Exit Sub
        SyncLock (CACHE_KEY)
            Dim temp As CProductTypeList = New CProductTypeList(Cache)
            temp.Add(Me)
            SetCache(temp)
        End SyncLock
    End Sub
    Protected Overrides Sub CacheUpdate()
        If CacheIsNull Then Exit Sub
        SyncLock (CACHE_KEY)
            Dim temp As CProductTypeList = New CProductTypeList(Cache)
            If Not temp.Contains(Me) Then
                temp.Remove(CacheGetById(temp))
                temp.Add(Me)
            End If
            SetCache(temp)
        End SyncLock
    End Sub
    Protected Overrides Sub CacheClear()
        Cache = Nothing
    End Sub
    Public Shared ReadOnly Property CacheIsNull() As Boolean
        Get
            Return IsNothing(CCache.Get(CACHE_KEY))
        End Get
    End Property
#End Region

#Region "ToXml"
    Protected Overrides Sub ToXml_Autogenerated(ByVal w As System.Xml.XmlWriter)
        Store(w, "TypeId", Me.TypeId)
        Store(w, "TypeName", Me.TypeName)
        Store(w, "TypeParentTypeId", Me.TypeParentTypeId)
        Store(w, "TypeParentIsRequired", Me.TypeParentIsRequired)
        Store(w, "TypeIsFree", Me.TypeIsFree)
        Store(w, "TypeCanHaveAudio", Me.TypeCanHaveAudio)
        Store(w, "TypeCanHavePdfOrWord", Me.TypeCanHavePdfOrWord)
        Store(w, "TypeCanHaveHtmlNotesOrPreview", Me.TypeCanHaveHtmlNotesOrPreview)
        Store(w, "TypeCanHaveVimeo", Me.TypeCanHaveVimeo)
        Store(w, "TypeCanHaveTranscript", Me.TypeCanHaveTranscript)
        Store(w, "TypeDescription", Me.TypeDescription)
    End Sub
#End Region

#Region "Audit Trail"
    Protected Overrides Function OriginalState(ByVal txOrNull As IDbTransaction) As SchemaAudit.CBaseDynamicAudited
        Return New CProductType(Me.DataSrc, Me.TypeId, txOrNull)
    End Function
#End Region


End Class